﻿using MongoDB.Bson;
using MongoDB.Driver;
using Project.Core.Common;
using Project.Core.IRepository.System;
using Project.Core.IServices.System;
using Project.Core.Model.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Project.Core.Services.System
{
    public class MenuService : IMenuService
    {
        IMenuRepository _menuRepository;

        public MenuService() { }

        public MenuService(IMenuRepository menuRepository)
        {
            _menuRepository = menuRepository;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Entity">实体</param>
        /// <returns></returns>
        public async Task<int> Add(Menu Entity)
        {
            return await _menuRepository.Insert(Entity);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Entity">实体</param>
        /// <returns></returns>
        public async Task<bool> Delete(Menu Entity)
        {
            return await _menuRepository.Update(Entity);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id">Id</param>
        /// <returns></returns>
        public async Task<bool> Delete(int Id)
        {
            return await _menuRepository.Delete(Id);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="expression">条件</param>
        /// <returns></returns>
        public async Task<List<Menu>> Query(Expression<Func<Menu, bool>> expression)
        {
            return await _menuRepository.Query(expression);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="expression">条件</param>
        /// <returns></returns>
        public async Task<PageDataList<Menu>> QueryByCondition(Expression<Func<Menu, bool>> expression, bool IsPage, int PageIndex, int PageSize, Expression<Func<Menu, object>> orderExpression, bool isAsc)
        {
            return await _menuRepository.QueryByCondition(expression, IsPage, PageIndex, PageSize, orderExpression, isAsc);
        }

        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="Entity"></param>
        /// <returns></returns>
        public async Task<bool> Update(Menu Entity)
        {
            return await _menuRepository.Update(Entity);
        }

        /// <summary>
        /// 查找单个数据
        /// </summary>
        /// <param name="expression">linq</param>
        /// <returns></returns>
        public async Task<Menu> Find(Expression<Func<Menu, bool>> expression)
        {
            return await _menuRepository.Find(expression);
        }
    }
}